package com.duanjw.bank.rate.core;

import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDate;

/**
 * @author duanjw
 * @date 2024/4/1
 */
@Data
@Builder
@AllArgsConstructor
public class BankRate {
    private LocalDate kaiShiZhiXingRiQi;

    private BigDecimal huoQiCunKuanLiLv;
    private BigDecimal zhengCunZhengQu3YueLiLv;
    private BigDecimal zhengCunZhengQu6YueLiLv;
    private BigDecimal zhengCunZhengQu1NianLiLv;
    private BigDecimal zhengCunZhengQu2NianLiLv;
    private BigDecimal zhengCunZhengQu3NianLiLv;
    private BigDecimal zhengCunZhengQu5NianLiLv;

    private BigDecimal lingCunZhengQu1NianLiLv;
    private BigDecimal lingCunZhengQu3NianLiLv;
    private BigDecimal lingCunZhengQu5NianLiLv;

    private BigDecimal dingHuoLiangBian3YueLiLv;
    private BigDecimal dingHuoLiangBian6YueLiLv;
    private BigDecimal dingHuoLiangBian1NianLiLv;


    private BigDecimal tongZhiCunKuan1TianLiLv;
    private BigDecimal tongZhiCunKuan7TianLiLv;

    /**
     * 协定存款
     */
    private BigDecimal xieDingCunKuanLiLv;

    public BankRate(LocalDate kaiShiZhiXingRiQi, String huoQiCunKuanLiLv, String zhengCunZhengQu3YueLiLv, String zhengCunZhengQu6YueLiLv, String zhengCunZhengQu1NianLiLv, String zhengCunZhengQu2NianLiLv, String zhengCunZhengQu3NianLiLv, String zhengCunZhengQu5NianLiLv, String lingCunZhengQu1NianLiLv, String lingCunZhengQu3NianLiLv, String lingCunZhengQu5NianLiLv, String dingHuoLiangBian3YueLiLv, String dingHuoLiangBian6YueLiLv, String dingHuoLiangBian1NianLiLv, String tongZhiCunKuan1TianLiLv, String tongZhiCunKuan7TianLiLv, String xieDingCunKuanLiLv) {
        this.kaiShiZhiXingRiQi = kaiShiZhiXingRiQi;
        this.huoQiCunKuanLiLv = formatNumber(huoQiCunKuanLiLv);
        this.zhengCunZhengQu3YueLiLv = formatNumber(zhengCunZhengQu3YueLiLv);
        this.zhengCunZhengQu6YueLiLv = formatNumber(zhengCunZhengQu6YueLiLv);
        this.zhengCunZhengQu1NianLiLv = formatNumber(zhengCunZhengQu1NianLiLv);
        this.zhengCunZhengQu2NianLiLv = formatNumber(zhengCunZhengQu2NianLiLv);
        this.zhengCunZhengQu3NianLiLv = formatNumber(zhengCunZhengQu3NianLiLv);
        this.zhengCunZhengQu5NianLiLv = formatNumber(zhengCunZhengQu5NianLiLv);
        this.lingCunZhengQu1NianLiLv = formatNumber(lingCunZhengQu1NianLiLv);
        this.lingCunZhengQu3NianLiLv = formatNumber(lingCunZhengQu3NianLiLv);
        this.lingCunZhengQu5NianLiLv = formatNumber(lingCunZhengQu5NianLiLv);
        this.dingHuoLiangBian3YueLiLv = formatNumber(dingHuoLiangBian3YueLiLv);
        this.dingHuoLiangBian6YueLiLv = formatNumber(dingHuoLiangBian6YueLiLv);
        this.dingHuoLiangBian1NianLiLv = formatNumber(dingHuoLiangBian1NianLiLv);
        this.tongZhiCunKuan1TianLiLv = formatNumber(tongZhiCunKuan1TianLiLv);
        this.tongZhiCunKuan7TianLiLv = formatNumber(tongZhiCunKuan7TianLiLv);
        this.xieDingCunKuanLiLv = formatNumber(xieDingCunKuanLiLv);
    }

    private BigDecimal formatNumber(String number) {
        if (StrUtil.isBlank(number)) {
            return null;
        }
        try {
            return new BigDecimal(number.trim().replace(" ", "")).stripTrailingZeros();
        } catch (Exception e) {
            System.out.println(number);
            e.printStackTrace();
        }
        return null;
    }
}
